<template>
  <el-dialog
    title="录像日期"
    :visible.sync="visible"
    width="30%"
    :before-close="closed"
  >
    <el-date-picker
      v-model="date"
      type="date"
      placeholder="选择日期"
      style="width: 100%;"
    />
    <div slot="footer">
      <el-button @click="closed">取 消</el-button>
      <el-button type="primary" @click="enterDate">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import moment from 'moment'

export default {
  name: 'DateDialog',
  data() {
    return {
      visible: false,
      date: new Date(),
      cameraInfo: null
    }
  },
  methods: {
    enterDate() {
      const _now = moment(new Date())
      const _date = moment(this.date)
      if (_now < _date) {
        this.$message.error('选择时间不能大于当前时间！')
        return false
      }
      const data = {
        cameraInfo: this.cameraInfo,
        start: _date.hour(0).minute(0).second(0).format('YYYY-MM-DDTHH:mm:ss'),
        end: _date.hour(23).minute(59).second(59).format('YYYY-MM-DDTHH:mm:ss')
      }
      new Promise(resolve => {
        this.$emit('get-replay-date', data)
        resolve(data)
      }).then(data => {
        this.closed()
      })
    },
    show(data) {
      this.visible = true
      this.cameraInfo = data
    },
    closed() {
      this.visible = false
      this.cameraInfo = null
      this.date = new Date()
    }
  }
}
</script>

<style scoped>

</style>